package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.Cyclopedia;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.CyclopediaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/cyclopedia")
public class CyclopediaController {

    @Autowired
    private CyclopediaService cyclopediaService;

    @GetMapping("/page")
    @Operation(summary =  "分页查询", description = "分页查询")
    public ServerResponseEntity<IPage<Cyclopedia>> getNoticePage(PageParam<Cyclopedia> page, Cyclopedia cyclopedia) {
        IPage<Cyclopedia> noticePage = cyclopediaService.page(page, new LambdaQueryWrapper<Cyclopedia>()
                .eq(Cyclopedia::getStatus, 1)
                .eq(Cyclopedia::getIsDel, 0).orderByDesc(Cyclopedia::getCreateTime));
        return ServerResponseEntity.success(noticePage);
    }

    @GetMapping("/info/{id}")
    @Operation(summary =  "百科信息", description = "百科信息")
    @Parameter(name = "id", description = "百科id")
    public ServerResponseEntity<Cyclopedia> getById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(cyclopediaService.getCyclopediaById(id));
    }



}
